<?php

namespace plugin\enterprise\app\controller;

use plugin\enterprise\app\Enterprise;
use plugin\enterprise\app\service\EnterprisePermissionService;
use plugin\enterprise\app\service\EnterpriseRoleService;
use plugin\owladmin\app\renderer\DrawerAction;
use plugin\owladmin\app\service\AdminPermissionService;

class EnterpriseRoleController extends \plugin\owladmin\app\controller\AdminRoleController
{
    protected string $serviceName = EnterpriseRoleService::class;
    public function __construct()
    {
        parent::__construct();
        $this->adminPrefix = Enterprise::config('enterprise.route.prefix');
        $this->queryPath = str_replace($this->adminPrefix . '/', '', request()->path());
    }



    protected function setPermission(): DrawerAction
    {
        return amis()->DrawerAction()
            ->label(admin_trans('admin.admin_role.set_permissions'))
            ->icon('fa-solid fa-gear')
            ->level('link')
            ->drawer(
                amis()->Drawer()
                    ->title(admin_trans('admin.admin_role.set_permissions'))
                    ->resizable()
                    ->closeOnOutside()
                    ->closeOnEsc()
                    ->body([
                        amis()->Form()
                            ->api(admin_url('system/enterprise_role_save_permissions'))
                            ->initApi($this->getEditGetDataPath())
                            ->mode('normal')
                            ->data(['id' => '${id}'])
                            ->body([
                                amis()->TreeControl()
                                    ->name('permissions')
                                    ->label()
                                    ->multiple()
                                    ->heightAuto()
                                    ->options(EnterprisePermissionService::make()->getTree())
                                    ->searchable()
                                    ->cascade()
                                    ->joinValues(false)
                                    ->extractValue()
                                    ->size('full')
                                    ->className('h-full b-none')
                                    ->inputClassName('h-full tree-full')
                                    ->labelField('name')
                                    ->valueField('id'),
                            ]),
                    ])
            );
    }
}